Skip to content

Conversation

@hathach
Copy link
Owner

@hathach hathach commented Nov 27, 2025

  • update vendor device to omit ep buf when dedicated hwfifo is supported
  • change tud_vendor_rx_cb() behavior, buffer and bufsize only available when CFG_TUD_VENDOR_RX_BUFSIZE = 0
  • add tud_vendor_n_read_discard(), refactor vendor device. Update webusb example for more robust
  • add tu_fifo_discard_n() and tu_edpt_stream_discard()

… when CFG_TUD_VENDOR_RX_BUFSIZE = 0

update vendor device to omit ep buf when dedicated hwfifo is supported
Copilot AI review requested due to automatic review settings November 27, 2025 11:44
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot finished reviewing on behalf of hathach November 27, 2025 11:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the vendor device implementation to support hardware endpoints with dedicated FIFO buffers, eliminating the need for local endpoint buffers in such configurations. This optimization reduces memory usage on hardware platforms with built-in FIFO support.

Key Changes:

  • Modified stream read/write functions to handle both buffered and unbuffered (dedicated HWFIFO) modes
  • Changed tud_vendor_rx_cb() API behavior: buffer/bufsize parameters are only valid when CFG_TUD_VENDOR_RX_BUFSIZE = 0
  • Added tu_fifo_discard_n() and tu_edpt_stream_discard() functions for discarding data without reading
  • Refactored vendor device structure and conditionally compiled endpoint buffers based on hardware capabilities

Reviewed changes

Copilot reviewed 8 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/tusb.c Updated stream write/read functions to support NULL ep_buf for dedicated HWFIFO mode; modified read behavior for non-FIFO mode
src/common/tusb_types.h Added tusb_buffer_t struct definition
src/common/tusb_private.h Added tu_edpt_stream_discard() inline helper function
src/common/tusb_fifo.h Reorganized API sections and added tu_fifo_discard_n() declaration
src/common/tusb_fifo.c Implemented tu_fifo_discard_n(), reorganized functions by API category, updated comments
src/class/vendor/vendor_device.h Updated API signatures (itf→idx), added callback documentation, refactored function declarations
src/class/vendor/vendor_device.c Restructured to conditionally compile endpoint buffers, refactored init logic, added find_vendor_itf() helper, updated callback invocation
src/class/cdc/cdc_device.c Simplified variable declarations for consistency with vendor device changes
examples/device/webusb_serial/src/main.c Refactored to use callback-driven approach instead of polling, removed cdc_task(), updated vendor RX callback to read from FIFO
examples/device/cdc_msc/src/main.c Added DCD state toggle alongside DSR in uart notification

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

…SIZE > 0

vendor_write_flush() and write_available()  only available when  CFG_TUD_VENDOR_TX_BUFSIZE > 0

tu_edpt_stream_read_xfer(rhport, &p_vendor->rx.stream);
} else if ( ep_addr == p_vendor->tx.stream.ep_addr ) {
tu_edpt_stream_read_xfer(rhport, &p_vendor->stream.rx); // prepare next data
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's useful to add a config whether next transfer is scheduled automatically or manually later in read_finished().

To give processing time for some commands.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we can have tud_vendor_configure() for manual read transfer including the intial xfer() when driver is open()

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add CFG_TUD_VENDOR_RX_MANUAL_XFER (default to 0) instead of dynamic configure, since I think this is only helpful with no-fifo RX.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, but I think the logic is inversed in vendord_open and vendord_xfer_cb ?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right, sorry. It is late here already.

@hathach hathach force-pushed the vendor-dedicated-hwfifo branch 3 times, most recently from 14cfcc4 to 84edff4 Compare November 27, 2025 16:22
@hathach hathach force-pushed the vendor-dedicated-hwfifo branch from 84edff4 to 6e9e9ce Compare November 27, 2025 16:24
@sonarqubecloud
Copy link

@hathach hathach merged commit 1618c58 into master Nov 27, 2025
196 of 200 checks passed
@hathach hathach deleted the vendor-dedicated-hwfifo branch November 27, 2025 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants